﻿CREATE PROCEDURE [dbo].[proc_Customer_DCreate_TongJi_Count]
	(
		@StartDate nvarchar(50),
		@EndDate nvarchar (50),
		@DepartmentId int,
		@Stext nvarchar(50)
	)
AS
begin
--	;WITH ChildDepartment(ID,DName,PId) AS
--	(
--		SELECT ID,DName,ParentID FROM department WHERE id=@departmentid
--	    
--		UNION ALL
--		SELECT department.ID,department.DName,department.ParentID FROM ChildDepartment AS d
--		INNER JOIN department ON d.ID = department.ParentID
--	)
	Declare @bmbh_T  varchar(30)
	Select @bmbh_T=bmbh From department Where id=@DepartmentId

	select count(id) from employee 
	where 
	employee.DepartmentId in(Select Id From department Where Left(bmbh,Len(@bmbh_T))=@bmbh_T) 
	and state<>5
	and ename like '%'+@Stext+'%'
end
